package org.vacoor.xqq.core.msg.chatmsg;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 基本消息
 * <p/>
 * <p/>
 * User: vacoor
 */
public abstract class BasicMsg {
    protected long msgId;   // 消息ID
    protected long fromUin; // 发送人, 对于多播消息(群/讨论组)为10000
    protected long toUin;   // 发给谁, 一般就是当前QQ
    protected long msgId2;  // ??

    /**
     * 允许消息体为空, 在反序列化时, 可以忽略该属性
     * 目前只有 好友消息 / 群组消息 / 讨论组消息 / 临时会话消息会有消息体
     */
    @JsonProperty("content")
    protected MsgBody msgBody = new MsgBody();

    /**
     * TODO 是否可以通过消息类型知道类型而不必通过 poll_type
     * ContactMsg 9  DiscuMsg 42 GroupMsg 43 InputNotifyMsg 121 KickMsg 48 SessMsg 140
     */
    protected int msgType;
    protected long replyIp; // 发送者IP(10进制)

    public long getMsgId() {
        return msgId;
    }

    public void setMsgId(long msgId) {
        this.msgId = msgId;
    }

    public long getFromUin() {
        return fromUin;
    }

    public void setFromUin(long fromUin) {
        this.fromUin = fromUin;
    }

    public long getToUin() {
        return toUin;
    }

    public void setToUin(long toUin) {
        this.toUin = toUin;
    }

    public long getMsgId2() {
        return msgId2;
    }

    public void setMsgId2(long msgId2) {
        this.msgId2 = msgId2;
    }

    public int getMsgType() {
        return msgType;
    }

    public void setMsgType(int msgType) {
        this.msgType = msgType;
    }

    public long getReplyIp() {
        return replyIp;
    }

    public void setReplyIp(long replyIp) {
        this.replyIp = replyIp;
    }

    public MsgBody getMsgBody() {
        return msgBody;
    }

    public void setMsgBody(MsgBody msgBody) {
        this.msgBody = msgBody;
    }

    @Override
    public String toString() {
        return getClass().getCanonicalName() + ":{" +
                "msgId:" + msgId +
                ", fromUin:" + fromUin +
                ", toUin:" + toUin +
                ", msgId2:" + msgId2 +
                ", msgType:" + msgType +
                ", replyIp:" + replyIp +
                "," + paramString() +
                ", " + msgBody +
                '}';
    }

    /**
     * 用于在父类toString() 中追加属性toString
     */
    protected abstract String paramString();
}
